var app = getApp(),
  $ = require("../../utils/httpHelper.js");
var address = require('../../utils/city.js')

Page({
  data: {
    height: 0,
    balance:0.00,
    banklist:[],//银行对象
    bankitem:[],//银行名字
    bankindex:[],//银行编号
    bankno:'',//选中银行编号
    index:-1,//选择银行数组的index
    userInfo:'',
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({ 
          height: res.windowHeight,
          userInfo: app.globalData.userInfo 
        })
      }
    })
    let par = {
      rd_session: app.globalData.userInfo.rd_session
    }
    $.httpPost("member_info", par, (data, err) => {
      this.setData({
        balance: data.data.data.balance
      })
    })
    $.httpPost("bank_list", par, (data, err) => {
      let name = []
      let index = []
      for (let item of data.data.list){
        name.push(item.name)
        index.push(item.bank_no)
      }
      this.setData({
        banklist: data.data.list,
        bankname:name,
        bankindex:index
      })
    })
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    let banknos = this.data.bankindex
    this.setData({
      bankno: banknos[e.detail.value],
      index: e.detail.value
    })
    console.log(this.data.bankno)
  },
  selectbank(){

  },
  inputmoney(e){
    this.setData({
      txmoney:e.detail.value
    })
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    let txm = this.data.txmoney
    let xingming = e.detail.value.xingming
    let yhcard = e.detail.value.yhcard
    let phone = e.detail.value.phone
    let bankno = this.data.bankno
    if (!this.checkinfo(txm, xingming, yhcard, phone, bankno)){
      wx.showToast({
        title: '不能是空',
      })
    }else{
      if (!this.checktxm(txm)){
        wx.showToast({
          title: '提现金额不满足',
        })
      }else{
        //开始提现post
        let par = {
          rd_session: app.globalData.userInfo.rd_session,
          name:xingming,
          card:yhcard,
          fee:txm,
          phone:phone,
          bank_no: bankno 
        }
        $.httpPost("apply_draw", par, (data, err) => {
          if(data.result == 'success'){
            wx.switchTab({
              url: '/pages/mine/mine',
            })
          }else{
            wx.showToast({
              title: data.message,
            })
          }
          
        })
      }
    }
    
  },
  checkinfo(txm, xingming, yhcard, phone, bankno) {
    if (app.check_empty(txm) || app.check_empty(xingming) || app.check_empty(yhcard) 
      || app.check_empty(phone) || app.check_empty(bankno)) {
      return false
    } else {
      return true
    }
  },
  checktxm(txm){
    if(txm>=100){
      return true
    }else{
      false
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})
